package com.heihei.itextdemo.service.impl;

import com.heihei.itextdemo.dto.CommonResponseDTO;
import com.heihei.itextdemo.entity.MajorEntity;
import com.heihei.itextdemo.mapper.MajorMapper;
import com.heihei.itextdemo.service.MajorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heihei.itextdemo.util.CommonUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 专业 服务实现类
 * </p>
 *
 * @author duanhengfei
 * @since 2020-12-04
 */
@Service
public class MajorServiceImpl extends ServiceImpl<MajorMapper, MajorEntity> implements MajorService {

    /**
     * 添加
     */
    @Override
    public CommonResponseDTO<String> add(MajorEntity entity) {
        //生成id
        entity.setId(CommonUtil.genUUID());
        boolean save = save(entity);
        if(save) {
            return CommonResponseDTO.forSuccess();
        }
        return CommonResponseDTO.forFail();
    }

    /**
     * 获取专业-班级-学生树结构
     */
    @Override
    public CommonResponseDTO<List<MajorEntity>> getTree() {
        List<MajorEntity> treeList = this.baseMapper.getTree();
        return CommonResponseDTO.forSuccess(treeList);
    }
}
